using System.Collections.Generic;
using UnityEngine;

public class TableTennisRateCaller : MonoBehaviour
{
	protected bool calledRate;

	public List<GameObject> noShowLayers = new List<GameObject>();

	public GameObject rateDialogLayer;

	private float timeSinceCheckedForUpdate;

	public float delayBetweenChecks = 5f;

	private void Awake()
	{
		timeSinceCheckedForUpdate = delayBetweenChecks;
	}

	private void OnApplicationPause(bool paused)
	{
		if (!paused)
		{
			CheckIfNeedsToShowRate();
		}
	}

	public void CheckIfNeedsToShowRate()
	{
		NavigationManager instance = NavigationManager.instance;
		if (!(instance == null) && !noShowLayers.Contains(instance.TopLayer()) && ScriptableObjectSingleton<RateSettings>.instance.ShouldShowRate())
		{
			ShowRate();
		}
	}

	public void ShowRate()
	{
		if (!(rateDialogLayer == null))
		{
			calledRate = true;
			NavigationManager.instance.PushModal(rateDialogLayer);
			Analytics.instance.rateAppRateShow();
		}
	}

	private void Update()
	{
		if (!calledRate)
		{
			timeSinceCheckedForUpdate += RealTime.deltaTime;
			if (timeSinceCheckedForUpdate > delayBetweenChecks)
			{
				CheckIfNeedsToShowRate();
				timeSinceCheckedForUpdate = 0f;
			}
		}
	}
}
